/*
 * @lc app=leetcode.cn id=12 lang=javascript
 *
 * [12] 整数转罗马数字
 */

// @lc code=start
/**
 * @param {number} num
 * @return {string}
 */
var intToRoman = function (num) {
    let nums = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]
    let strs = ['I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M']
    let ans = ''
    while (num > 0) {
        for (let i = nums.length - 1; i >= 0; i--) {
            if (num >= nums[i]) {
                ans = ans + strs[i]
                num = num - nums[i]
                break
            }
        }
    }
    return ans
};
// @lc code=end
// @after-stub-for-debug-begin
module.exports = intToRoman;
// @after-stub-for-debug-end